package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.act.PotentialListAct;
import com.chuji.crmcj.bean.PotenMagInfo;
import com.chuji.crmcj.utils.CommonUtil;
import com.chuji.crmcj.utils.NumberUtils;

import java.util.List;

/**
 * Created by w.pitt on 2016/2/26.
 */
public class potentMagAda extends BaseAdapter {

    private Context mContext;

    private List<PotenMagInfo.ApiParamObjEntity> mPotenMagInfo;
    private MagViewHoler magHolder;
    private LinearLayout ll_mag_order_detail;

    public potentMagAda(PotentialListAct potentialListAct, List<PotenMagInfo.ApiParamObjEntity> potenMagInfo) {
        this.mContext = potentialListAct;
        this.mPotenMagInfo = potenMagInfo;
    }

    @Override
    public int getCount() {
        return mPotenMagInfo.isEmpty() ? 0 : mPotenMagInfo.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.listview_mag_client_lose, null);
            magHolder = new MagViewHoler();
            magHolder.ll_mag_order_detail= (LinearLayout) convertView.findViewById(R.id.ll_mag_order_detail);
            magHolder.iv_no_read = (ImageView) convertView.findViewById(R.id.iv_no_read);
            magHolder.tv_client_name = (TextView) convertView.findViewById(R.id.tv_client_name);
            magHolder.tv_car_type = (TextView) convertView.findViewById(R.id.tv_car_type);
            magHolder.tv_client_num = (TextView) convertView.findViewById(R.id.tv_client_num);
            magHolder.tv_want_car = (TextView) convertView.findViewById(R.id.tv_want_car);
            magHolder.tv_salesman_name = (TextView) convertView.findViewById(R.id.tv_salesman_name);
            magHolder.tv_handle_time = (TextView) convertView.findViewById(R.id.tv_handle_time);
            magHolder.iv_level = (ImageView) convertView.findViewById(R.id.iv_order_level);
            magHolder.tv_kongbai=(TextView)convertView.findViewById(R.id.tv_kongbai);
            convertView.setTag(magHolder);
        } else {
            magHolder = (MagViewHoler) convertView.getTag();
        }
        magHolder.iv_level.setVisibility(View.VISIBLE);
        magHolder.tv_kongbai.setVisibility(View.VISIBLE);
        magHolder.ll_mag_order_detail.setVisibility(View.VISIBLE);
        magHolder.iv_level.setImageDrawable(CommonUtil.getLevelIcon(mPotenMagInfo.get(position).getCustomerLevel()));
        magHolder.tv_client_name.setText(mPotenMagInfo.get(position).getName());
        magHolder.tv_car_type.setText(mPotenMagInfo.get(position).getCarModel());
        magHolder.tv_salesman_name.setText(mPotenMagInfo.get(position).getRealName());
        magHolder.tv_want_car.setText("订单车型");
//        magHolder.tv_handle_time.setText(mPotenMagInfo.getApiParamObj().get(position).getLastTime());
        String custormerTel = mPotenMagInfo.get(position).getTel();
        if (custormerTel.length() == 11 || custormerTel.length() == 7) {
            magHolder.tv_client_num.setText(NumberUtils.parsePhoneNumber(custormerTel));
        }else{
            magHolder.tv_client_num.setText(custormerTel);
        }
        return convertView;
    }

    public List<PotenMagInfo.ApiParamObjEntity> getList() {
        return mPotenMagInfo;
    }


    static class MagViewHoler {
        private TextView tv_client_name;
        private TextView tv_car_type;
        private TextView tv_client_num;
        private TextView tv_want_car;
        private TextView tv_salesman_name;
        private TextView tv_handle_time;
        private ImageView iv_no_read;
        private ImageView iv_level;
        private LinearLayout ll_mag_order_detail;
        private View line;
        private TextView tv_kongbai;
    }
}
